/**********************************************************************
 * Filename: Cidade.java
 * Created: 2012/04/30
 * @author Fernando Brito e Abreu
 **********************************************************************/
package org.quasar.CopaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Cidade {
	public static Set<Cidade> allInstances = new HashSet<Cidade>();

	private boolean capital;
	private String nome;
	private int populacao;
	private Pais pais;

	/**********************************************************************
	 * Default constructor
	 **********************************************************************/
	public Cidade() {
		allInstances.add(this);
	}

	/**********************************************************************
	 * Parameterized constructor
	 * 
	 * @param capital
	 *            the capital to initialize
	 * @param nome
	 *            the nome to initialize
	 * @param populacao
	 *            the populacao to initialize
	 * @param pais
	 *            the pais to initialize
	 **********************************************************************/
	public Cidade(boolean capital, String nome, int populacao, Pais pais) {
		this.capital = capital;
		this.nome = nome;
		this.populacao = populacao;
		this.pais = pais;
		allInstances.add(this);
	}

	/**********************************************************************
	 * Standard attribute getter
	 * 
	 * @return the capital of the cidade
	 **********************************************************************/
	public boolean capital() {
		return capital;
	}

	/**********************************************************************
	 * Standard attribute setter
	 * 
	 * @param capital
	 *            the capital to set
	 **********************************************************************/
	public void setCapital(boolean capital) {
		this.capital = capital;
	}

	/**********************************************************************
	 * Standard attribute getter
	 * 
	 * @return the nome of the cidade
	 **********************************************************************/
	public String nome() {
		return nome;
	}

	/**********************************************************************
	 * Standard attribute setter
	 * 
	 * @param nome
	 *            the nome to set
	 **********************************************************************/
	public void setNome(String nome) {
		this.nome = nome;
	}

	/**********************************************************************
	 * Standard attribute getter
	 * 
	 * @return the populacao of the cidade
	 **********************************************************************/
	public int populacao() {
		return populacao;
	}

	/**********************************************************************
	 * Standard attribute setter
	 * 
	 * @param populacao
	 *            the populacao to set
	 **********************************************************************/
	public void setPopulacao(int populacao) {
		this.populacao = populacao;
	}

	/**********************************************************************
	 * ONE2MANY getter for Cidade[*] <-> Pais[1]
	 * 
	 * @return the pais of the cidade
	 **********************************************************************/
	public Pais pais() {
		return pais;
	}

	/**********************************************************************
	 * ONE2MANY setter for Cidade[*] <-> Pais[1]
	 * 
	 * @param pais
	 *            the pais to set
	 **********************************************************************/
	public void setPais(Pais pais) {
		this.pais = pais;
	}

	/**********************************************************************
	 * ONE2MANY getter for Cidade[1] <-> Estadio[*]
	 * 
	 * @return the estadios of the cidade
	 **********************************************************************/
	public Set<Estadio> estadios() {
		Set<Estadio> result = new HashSet<Estadio>();
		for (Estadio x : Estadio.allInstances)
			if (x.cidade() == this)
				result.add(x);
		return result;
	}

	/**********************************************************************
	 * ONE2MANY setter for Cidade[1] <-> Estadio[*]
	 * 
	 * @param estadios
	 *            the estadios to set
	 **********************************************************************/
	public void setEstadios(Set<Estadio> estadios) {
		for (Estadio x : estadios)
			x.setCidade(this);
	}

	/**********************************************************************
	 * User-defined operation specified in SOIL/OCL
	 * 
	 * @param nome
	 *            the nome to set
	 * @param populacao
	 *            the populacao to set
	 * @param capital
	 *            the capital to set
	 * @param pais
	 *            the pais to set
	 **********************************************************************/
	public void inicializa(String nome, int populacao, boolean capital,
			Pais pais) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	/**********************************************************************
	 * Object serializer
	 **********************************************************************/
	public String toString() {
		return "Cidade [capital=" + capital + ", nome=" + nome + ", populacao="
				+ populacao + ", pais=" + pais + "]\n";
	}

}
